

package utils;

import codegen.BlueTemplate;
import codegen.FilesParser;
import codegen.VelocityProcessor;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
import java.io.StringWriter;
import java.util.ArrayList;
import org.apache.velocity.Template;
import org.apache.velocity.VelocityContext;
import org.apache.velocity.app.Velocity;
import org.apache.velocity.exception.ParseErrorException;
import org.apache.velocity.exception.ResourceNotFoundException;
import xmibase.XmiAttribute;
import xmibase.XmiClass;
import xmibase.XmiPackage;



/**
 *
 * @author Felipe Gutierrez
 */
public class FelipeUtils {

    ArrayList<XmiClass> listPranchetas;
    ArrayList<XmiClass> listAbas;
    ArrayList<XmiClass> listClass;
    ArrayList<XmiClass> listManBean;
    ArrayList<XmiClass> listOneClass;
    ArrayList<XmiAttribute> listAttributeAssoc;
    ArrayList<XmiAttribute> listAttributeClasses;
    ArrayList<String> listTypeAssoc;
    ArrayList<Integer> listMult;


    //ArrayList<String> listManBean;
    VelocityContext context;
    VelocityContext context2;
    VelocityContext context3;
    VelocityContext context4;
     VelocityContext context5;
    Velocity velocity ;

    public FelipeUtils(){

        this.listPranchetas = new ArrayList<XmiClass>();
        this.listAbas = new ArrayList<XmiClass>();
        this.listClass = new ArrayList<XmiClass>();
        this.listManBean = new ArrayList<XmiClass>();
        this.listOneClass = new ArrayList<XmiClass>();
        this.listMult = new ArrayList<Integer>();
        this.listAttributeAssoc = new ArrayList<XmiAttribute>();
        this.listTypeAssoc = new ArrayList<String>();
        this.listAttributeClasses = new ArrayList<XmiAttribute>();
        context = new VelocityContext();
        context2 = new VelocityContext();
        context3 = new VelocityContext();
        context4 = new VelocityContext();
        context5 = new VelocityContext();
        velocity = new Velocity();
    }

public String packageName(String c){

    String s[] = c.split("\\.");
           if(s.length != 3){
               return null;
           }

           return s[1];



}

public String subPackageName(String c){

     String s[] = c.split("\\.");
           if(s.length != 3){
               return null;
           }
           System.out.println(s.length);


            return s[2];

}


public String visualization(String c){

    String s[] = c.split("\\.");
           if(s.length != 3){
               return null;
           }
           System.out.println(s.length);




            return s[0];


}public void generateFiles(String fileName, String module_PKG, String module_PKG_s,String module_visu ,String appName,
			String content, String outDir) throws IOException {

        String subPackage = module_PKG_s;
		if (outDir == null) {
			throw new FileNotFoundException("URL is null");
		}

		File dir;
		dir = new File(outDir);
		if (!dir.exists()) {
			throw new IOException("Directory does not exists.(" + dir.getPath()
					+ ")");
		}
		if (!dir.isDirectory()) {
			throw new IOException("Input parameter must be a directory.("
					+ dir.getPath() + ")");
		}
		

		int count = 0;

		String pack = module_PKG;

		
		String directoryPath = dir.getPath();
		if ((pack != null) && (!pack.equals(""))) {
			directoryPath = createDirectoriesSRC(dir,module_visu, pack,subPackage, appName);
		}

		

		pack = pack.replace('.', File.separator.charAt(0));
		
		String fname = directoryPath + "\\" + fileName;//+ File.separator + pack + File.separator + fileName;

		FileWriter fw = new FileWriter(fname);

		fw.write(content);
		fw.close();

	}

           public void generateEntityFiles(String fileName , String content , String module_visu, String outDir )throws IOException {


		if (outDir == null) {
			throw new FileNotFoundException("URL is null");
		}

		File dir;
		dir = new File(outDir);
		if (!dir.exists()) {
			throw new IOException("Directory does not exists.(" + dir.getPath()
					+ ")");
		}
		if (!dir.isDirectory()) {
			throw new IOException("Input parameter must be a directory.("
					+ dir.getPath() + ")");
		}


		int count = 0;



		
		String directoryPath = dir.getPath();

			directoryPath = this.createDirectoriesEntity(dir,module_visu);


		
		String fname = directoryPath + "\\" + fileName;//+ File.separator + pack + File.separator + fileName;

		FileWriter fw = new FileWriter(fname);

		fw.write(content);
		fw.close();





        }

public String createDirectoriesEntity(File dir , String visuPack){

            String newRoot = dir.getAbsolutePath();

		
		String[] directoriesSRC = {visuPack};
        
		for (int i = 0; i < directoriesSRC.length ; i++) {


            File auxDir = new File(newRoot + "\\" + directoriesSRC[i]);
            if (!auxDir.exists()) {
				auxDir.mkdir();
			}
            newRoot = newRoot + "\\" + directoriesSRC[i];

            }


			//newRoot += directoriesSRC[i] + File.separator;

		return newRoot;


        }

       
	public String createDirectoriesSRC(File dir,String visuPack, String pack,String subPackage, String appName) {
		String newRoot = dir.getAbsolutePath();

		
		String[] directoriesSRC = {"com" , visuPack , pack , subPackage , "backbean"};
       
		for (int i = 0; i < directoriesSRC.length ; i++) {


            File auxDir = new File(newRoot + "\\" + directoriesSRC[i]);
            if (!auxDir.exists()) {
				auxDir.mkdir();
			}
            newRoot = newRoot + "\\" + directoriesSRC[i];

            }


			

		return newRoot;
	}


public void genFacesConfig(BlueTemplate tmpBlueTemplate, XmiPackage pack , String outDir )
         throws ResourceNotFoundException, ParseErrorException, Exception {

     StringWriter output = new StringWriter();
     FelipeUtils utils = new FelipeUtils();
     for(XmiClass classe : pack.getClasses()){
            if(!(classe.getName().equals("String"))){
                 this.listManBean.add(classe);
            }
            
            
            
      }
    

     context3.put("listClass", this.listManBean);
     context3.put("felipeutils",utils);
     Template template = velocity.getTemplate(tmpBlueTemplate
						.getAbsolutePath());
				template.merge(context3, output);
               
                    File dir;
                    dir = new File(outDir+"\\faces-config.xml");

                    FileWriter f = new FileWriter(dir);
                    f.write(output.toString());
                    f.close();

}

public void executeGenFacesConfig(ArrayList<String> listTemplatesRoles , VelocityProcessor vp , XmiPackage pack , String outDir) throws Exception {


velocity.setProperty("file.resource.loader.path", "");
		velocity.init();

                
                FelipeUtils utils = new FelipeUtils();
                context3.put("felipeUtils", utils);
		

		vp.listFiles(vp.templatesPath);
		vp.loadTemplates();
		ArrayList<BlueTemplate> auxFilteredTemplates = new ArrayList<BlueTemplate>();
		auxFilteredTemplates = vp.filterTemplates(listTemplatesRoles);

		for (BlueTemplate tmpBlueTemplate : auxFilteredTemplates) {
			System.out.println("Template: " + tmpBlueTemplate.getName());
			System.out.println("TESTE");
                    genFacesConfig(tmpBlueTemplate , pack , outDir);

		}



}

public void executeGenClass(ArrayList<String> listTemplatesRoles , VelocityProcessor vp , XmiPackage pack , String outDir) throws Exception {


                

                velocity.setProperty("file.resource.loader.path", "");
		velocity.init();
		EntityUtils entityUtils = new EntityUtils();
		GenUtils reportBeanUtils = new GenUtils();
                FelipeUtils utils = new FelipeUtils();
		context.put("entityUtils", entityUtils);
		context.put("reportBeanUtils", reportBeanUtils);
                context.put("felipeUtils", utils);
		vp.listFiles(vp.templatesPath);
		vp.loadTemplates();
		ArrayList<BlueTemplate> auxFilteredTemplates = new ArrayList<BlueTemplate>();
		auxFilteredTemplates = vp.filterTemplates(listTemplatesRoles);

		for (BlueTemplate tmpBlueTemplate : auxFilteredTemplates) {
			System.out.println("Template: " + tmpBlueTemplate.getName());
			if (true) {
				generateClassFelipeProject(tmpBlueTemplate ,pack ,outDir, vp );
			} else {
				vp.generatePackage(tmpBlueTemplate);
			}

		}
	}



        public void executeGenIcefaces(ArrayList<String> listTemplatesRoles , VelocityProcessor vp , XmiPackage pack , String outDir) throws Exception {



                velocity.setProperty("file.resource.loader.path", "");
		velocity.init();

                EntityUtils entityUtils = new EntityUtils();
		GenUtils reportBeanUtils = new GenUtils();
                FelipeUtils utils = new FelipeUtils();
                context2.put("felipeUtils", utils);
		context2.put("entityUtils", entityUtils);
		context2.put("reportBeanUtils", reportBeanUtils);

		vp.listFiles(vp.templatesPath);
		vp.loadTemplates();
		ArrayList<BlueTemplate> auxFilteredTemplates = new ArrayList<BlueTemplate>();
		auxFilteredTemplates = vp.filterTemplates(listTemplatesRoles);

		for (BlueTemplate tmpBlueTemplate : auxFilteredTemplates) {
			System.out.println("Template: " + tmpBlueTemplate.getName());
			System.out.println("TESTE");
                    generateIcefaces(tmpBlueTemplate , pack , outDir);

		}
	}

        public void getClassAssoc(XmiClass c, XmiPackage pack){
            
            FormatationUtils formatation = new FormatationUtils();
            

                if(!(c.getAssociatesAttributes().isEmpty())){
               for(int i = 0 ; i < c.getAssocitesAttributes().size() ; i++){

                        System.out.println("CLASSE C : " + c.getName());

                         String d = formatation.upperFirst(c.getAssociatesAttributes().get(i).getName());
                         System.out.println("CLASSE COMPARACAO: " + d);

                         for(XmiClass classe2 : pack.getClasses()){
                                 
                                  if(classe2.getName().equals(d)){
                                  if(!(this.listOneClass.contains(classe2))){
                                      this.listOneClass.add(classe2);
                                      System.out.println("CLASSE ADD: " + classe2.getName());
                                      this.getClassAssoc(classe2, pack);
                                  }

                                  }



                             }

               }


                }
                        


            
        }

        public XmiClass getAntClasse(XmiClass c){

            for(int i = 0; i < this.listOneClass.size(); i++){

                if(this.listOneClass.get(i).equals(c)){

                    return this.listOneClass.get(i - 1);

                }


            }

            return null;
        }

        public int getSucClasse(XmiClass c , ArrayList<XmiClass> array ){
            int j = 50;


             for(int i = 0; i < array.size(); i++){

                if(array.get(i).equals(c)){

                    j = i;

                }


            }

            return j + 1;
        }

        public String getNameSucClasse(XmiClass c , ArrayList<XmiClass> array ){

            String nome = "";

             for(int i = 0; i < array.size(); i++){

                if(array.get(i).equals(c)){

                    nome = array.get(i + 1).getName();

                }


        }
            return nome;
        }



        

        public XmiClass getNameClassAssoc(XmiClass c, XmiPackage pack){

            XmiClass cl = new XmiClass() ;
            FormatationUtils formatation = new FormatationUtils();
            


               for(int i = 0 ; i < c.getAssocitesAttributes().size() ; i++){



                         String d = formatation.upperFirst(c.getAssociatesAttributes().get(i).getName());
                         
                   
                         for(XmiClass classe2 : pack.getClasses()){

                             if(classe2.getName().equals("d")){
                                cl =  classe2;

                                 


                                 }



                             }

               }

               return cl;

       }

        public void executeGenIPopup(ArrayList<String> listTemplatesRoles , VelocityProcessor vp , XmiPackage pack , String outDir) throws Exception {

            velocity.setProperty("file.resource.loader.path", "");
		velocity.init();

                
               

		vp.listFiles(vp.templatesPath);
		vp.loadTemplates();
		ArrayList<BlueTemplate> auxFilteredTemplates = new ArrayList<BlueTemplate>();
		auxFilteredTemplates = vp.filterTemplates(listTemplatesRoles);

		for (BlueTemplate tmpBlueTemplate : auxFilteredTemplates) {
			System.out.println("Template: " + tmpBlueTemplate.getName());
			System.out.println("TESTE");
                    this.generateIPopup(tmpBlueTemplate , pack , outDir);

		}
	}


         public void executeGenHtml(ArrayList<String> listTemplatesRoles , VelocityProcessor vp , XmiPackage pack , String outDir) throws Exception {

            velocity.setProperty("file.resource.loader.path", "");
		velocity.init();




		vp.listFiles(vp.templatesPath);
		vp.loadTemplates();
		ArrayList<BlueTemplate> auxFilteredTemplates = new ArrayList<BlueTemplate>();
		auxFilteredTemplates = vp.filterTemplates(listTemplatesRoles);

		for (BlueTemplate tmpBlueTemplate : auxFilteredTemplates) {
			System.out.println("Template: " + tmpBlueTemplate.getName());
			System.out.println("TESTE");
                    this.generateClassHtml(tmpBlueTemplate , pack , outDir);

		}
	}

        public ArrayList<XmiAttribute> getAssocAttr(XmiClass c){

            ArrayList<XmiAttribute> array = new ArrayList<XmiAttribute>();
            for(int d = 0 ; d < c.getAssociatesAttributes().size() ; d++){

                array.add(c.getAssociatesAttributes().get(d));

            }

            return array;
        }

        public XmiClass getClassAttrAssoc(String x , XmiPackage pack){
            FormatationUtils form = new FormatationUtils();

            for(XmiClass c : pack.getClasses()){

                if(c.getName().equals(form.upperFirst(x))){
                    return c;
                }
            }

            return null;


        }


        public ArrayList<XmiAttribute> getAttrClass(XmiClass c){
            ArrayList<XmiAttribute> array = new ArrayList<XmiAttribute>();
            for(int f = 0 ; f < c.getAttributes().size() ; f++){

                array.add(c.getAttributes().get(f));
            }

            return array;

        }

        public String getFirstAttr(XmiClass c){
            String x = "";
            if(!(c.getAttributes().isEmpty())){
               x =  c.getAttributes().get(0).getName();

            }
            return x;
        }

        public ArrayList<String> getTypeAssoc(XmiClass c){

            ArrayList<String> array = new ArrayList<String>();
            ArrayList<XmiAttribute> array2 = new ArrayList<XmiAttribute>();
            array2 = this.getAssocAttr(c);

            for(int g = 0 ; g < array2.size() ; g++){
               array.add(array2.get(g).getAggregation());

            }

            return array;
            


        }

        public ArrayList<Integer> getMult(XmiClass c){

           

            ArrayList<Integer> array = new ArrayList<Integer>();
            ArrayList<XmiAttribute> array2 = new ArrayList<XmiAttribute>();
            array2 = this.getAssocAttr(c);

            for(int g = 0 ; g < array2.size() ; g++){
                array.add(array2.get(g).getUpperMultiplicity());

            }
            return array;
        }

        public int getTamListClasses(){

            int m = 2;
            if(this.listOneClass.size() == 1){

                m = 1;

            }
            return m;



        }
        public int getNoneAttrAssoc(XmiClass c){
            int n = 1 ;
            ArrayList<XmiAttribute> array = new ArrayList<XmiAttribute>();
            array = this.getAssocAttr(c);
            if(array.size() == 0){

                n = 0;

            }


            return n;



        }

        public int getNoneMult(XmiClass c ){

            int j = 1;
            ArrayList<Integer> i = new ArrayList<Integer>();
            i = this.getMult(c);
            if(i.size() == 0){

                j = 0;

            }
            return j;
        }

        public void generateClassHtml(BlueTemplate tmpBlueTemplate , XmiPackage pack , String outDir)
        throws ResourceNotFoundException, ParseErrorException, Exception {
            FormatationUtils formatation = new FormatationUtils();
            FelipeUtils utils = new FelipeUtils();
            EntityUtils entityUtils = new EntityUtils();
	     GenUtils reportBeanUtils = new GenUtils();

             for(XmiClass classe : pack.getClasses()){
                   if(!(classe.getName().equals("String"))){
                       if(!(classe.getPackageName().equals("entity"))){
                       this.context5.put("classe", classe);
                        StringWriter output = new StringWriter();


                      this.listAttributeAssoc = this.getAssocAttr(classe);
                            System.out.println("Nome CLasse ASSOC: " + classe.getName());
                      for(int i = 0 ; i < this.listAttributeAssoc.size() ; i++){
                            System.out.println(this.listAttributeAssoc.size());
                            System.out.println("Atributos associandos : " + this.listAttributeAssoc.get(i).getName());

                        }
                      this.listAttributeClasses = this.getAttrClass(classe);
                      this.listTypeAssoc = this.getTypeAssoc(classe);
                       for(int i = 0 ; i < this.listTypeAssoc.size() ; i++){

                            System.out.println("Tipos Associados : " + this.listTypeAssoc.get(i).toString());

                        }

                     


                       this.listOneClass.add(classe);
                       this.getClassAssoc(classe,pack);
                       

                        for(int i = 0 ; i < this.listOneClass.size() ; i++){
                           System.out.println("T : " + this.listOneClass.size());
                            System.out.println("Classes Relacoes : " + this.listOneClass.get(i).getName());

                        }
                        int x = 0;
                        if(this.listOneClass.size() == 1){
                            x = 1;

                        }
                        if(this.listOneClass.size() > 1){
                            x = 2;


                        }
                        if(this.listOneClass.isEmpty()){

                            x = 0;

                        }
                        context5.put("numberCla", x);
                        this.listMult = this.getMult(classe);

                        for(int i = 0 ; i < this.listMult.size() ; i++){
                             System.out.println("TAMANHO MULTIPLICIDADE " + this.listMult.size());
                            System.out.println("Multiplicidade : " + this.listMult.get(i).toString());

                        }









                this.context5.put("felipeUtils", utils)  ;
                this.context5.put("utilsF", reportBeanUtils);
                this.context5.put("listOneC", this.listOneClass);

                this.context5.put("formatation", formatation);
                this.context5.put("listAttrAssoc", this.listAttributeAssoc);
                this.context5.put("listAttrClass", this.listAttributeClasses);
                 this.context5.put("listTypeAssoc", this.listTypeAssoc);
                 this.context5.put("listMult", this.listMult);


                Template template = velocity.getTemplate(tmpBlueTemplate
						.getAbsolutePath());
				template.merge(context5, output);


               // if(x == Application.getClasses().size() - 1 ){
                   // System.out.println("VEZ");
                    File dir;
                    dir = new File(outDir + "\\" + classe.getName() + ".html");

                    FileWriter f = new FileWriter(dir);
                    f.write(output.toString());
                    f.close();

                    context5.remove("numberCla");
                    context5.remove("felipeUtils");
                    context5.remove("classe");
                 context5.remove("listOneC");
                 context5.remove("formatation");
                  context5.remove("listAttrAssoc");
                  context5.remove("listAttrClass");
                  context5.remove("listTypeAssoc");
                  context5.remove("listMult");

                  this.listOneClass.clear();



                 this.listMult.clear();



                 this.listTypeAssoc.clear();



                 this.listAttributeClasses.clear();



                 this.listAttributeAssoc.clear();


               }





                   }
            }
        }








        public void generateIPopup(BlueTemplate tmpBlueTemplate , XmiPackage pack , String outDir)
         throws ResourceNotFoundException, ParseErrorException, Exception {
            FormatationUtils formatation = new FormatationUtils();
            FelipeUtils utils = new FelipeUtils();
            EntityUtils entityUtils = new EntityUtils();
	     GenUtils reportBeanUtils = new GenUtils();


            
            
            
            for(XmiClass classe : pack.getClasses()){
               if(classe.getPackageName().equals("entity")){
                 
               
                 if(!(classe.getName().equals("String"))){
                        this.context4.put("classe", classe);
                        StringWriter output = new StringWriter();
                        
                      
                      this.listAttributeAssoc = this.getAssocAttr(classe);
                            System.out.println("Nome CLasse : " + classe.getName());
                      for(int i = 0 ; i < this.listAttributeAssoc.size() ; i++){
                            System.out.println(this.listAttributeAssoc.size());
                            System.out.println("Atributos associandos : " + this.listAttributeAssoc.get(i).getName());

                        }
                      this.listAttributeClasses = this.getAttrClass(classe);
                      this.listTypeAssoc = this.getTypeAssoc(classe);
                       for(int i = 0 ; i < this.listTypeAssoc.size() ; i++){

                            System.out.println("Tipos Associados : " + this.listTypeAssoc.get(i).toString());

                        }

                        
                       this.listOneClass.add(classe);
                       this.getClassAssoc(classe,pack);
                      
                       
                        for(int i = 0 ; i < this.listOneClass.size() ; i++){
                           System.out.println("T : " + this.listOneClass.size());
                            System.out.println("Classes Relacoes : " + this.listOneClass.get(i).getName());

                        }
                        int x = 0;
                        if(this.listOneClass.size() == 1){
                            x = 1;

                        }
                        if(this.listOneClass.size() > 1){
                            x = 2;


                        }
                        if(this.listOneClass.isEmpty()){

                            x = 0;

                        }
                        context4.put("numberCla", x);
                        this.listMult = this.getMult(classe);

                        for(int i = 0 ; i < this.listMult.size() ; i++){
                             System.out.println("TAMANHO MULTIPLICIDADE " + this.listMult.size());
                            System.out.println("Multiplicidade : " + this.listMult.get(i).toString());

                        }





                    

               
                
                this.context4.put("felipeUtils", utils)  ;
                this.context4.put("utilsF", reportBeanUtils);
                this.context4.put("listOneC", this.listOneClass);
                
                this.context4.put("formatation", formatation);
                this.context4.put("listAttrAssoc", this.listAttributeAssoc);
                this.context4.put("listAttrClass", this.listAttributeClasses);
                 this.context4.put("listTypeAssoc", this.listTypeAssoc);
                 this.context4.put("listMult", this.listMult);


                Template template = velocity.getTemplate(tmpBlueTemplate
						.getAbsolutePath());
				template.merge(context4, output);


               // if(x == Application.getClasses().size() - 1 ){
                   // System.out.println("VEZ");
                    File dir;
                    dir = new File(outDir + "\\" + classe.getName() + ".jspx");

                    FileWriter f = new FileWriter(dir);
                    f.write(output.toString());
                    f.close();
                    
                    context4.remove("numberCla");
                    context4.remove("felipeUtils");
                    context4.remove("classe");
                 context4.remove("listOneC");
                 context4.remove("formatation");
                  context4.remove("listAttrAssoc");
                  context4.remove("listAttrClass");
                  context4.remove("listTypeAssoc");
                  context4.remove("listMult");

                  this.listOneClass.clear();
                 
                  
                  
                 this.listMult.clear();
                 

                  
                 this.listTypeAssoc.clear();
                 

                  
                 this.listAttributeClasses.clear();
                 

                  
                 this.listAttributeAssoc.clear();
                 

               }
//            }else{
//                    StringWriter output = new StringWriter();
//                  ArrayList<XmiAttribute> arrayAttrClass = this.getAttrClass(classe);
//                  context4.put("arrayAttrClasses", arrayAttrClass);
//                  context4.put("classe", classe);
//                  Template template = velocity.getTemplate(tmpBlueTemplate
//						.getAbsolutePath());
//				template.merge(context4, output);
//                   File dir;
//                    dir = new File(outDir + "\\" + classe.getName() + ".jspx");
//
//                    FileWriter f = new FileWriter(dir);
//                    f.write(output.toString());
//                    f.close();
//                    context4.remove("arrayAttrClasses");
//                   context4.remove("classe");
//
//
//                             arrayAttrClass.clear();
//                 
//
//                        }
            }
            }
        }
        


        public void generateIcefaces(BlueTemplate tmpBlueTemplate , XmiPackage pack , String outDir)
        throws ResourceNotFoundException, ParseErrorException, Exception {
        FelipeUtils utils = new FelipeUtils();
        StringWriter output = new StringWriter();

        for(XmiClass classe : pack.getClasses()){
            if(!(classe.getName().equals("String")) ){

                System.out.println("Nome classe : " + classe.getName());
                for(int i = 0 ; i < classe.getAssocitesAttributes().size() ; i++){
                System.out.println("Atributos : " + classe.getAssocitesAttributes().get(i).getName());
                
                System.out.println("Agragacao : " + classe.getAssocitesAttributes().get(i).getAggregation());
                System.out.println("Multiplicidade : " + classe.getAssocitesAttributes().get(i).getUpperMultiplicity());
                System.out.println("Separa");
                }
                 for(int i = 0 ; i < classe.getAttributes().size() ; i++){
                     System.out.println("Nome classe2 : " + classe.getName());
                     System.out.println("Atributos2 : " + classe.getAttributes().get(i).getName());
                    
                 }

            }

            if(utils.packageName(classe.getPackageName())!= null){
            System.out.println(classe.getName() + "\n");

            System.out.println("PACOTE  : " + utils.packageName(classe.getPackageName()));
            System.out.println("SUBPACOTE  : " + utils.subPackageName(classe.getPackageName()));
            this.listClass.add(classe);
            }
        }

        int x = 0;
        for(XmiClass classe : pack.getClasses()){
             boolean have2 = false;
            if(utils.packageName(classe.getPackageName()) != null){
            System.out.println(utils.packageName(classe.getPackageName()));

            if(x == 0){

               this.listPranchetas.add(classe);


            }


           for ( XmiClass classe2 : pack.getClasses() ){
               if(utils.packageName(classe2.getPackageName()) != null){
               if(!(utils.packageName(classe.getPackageName()).equals(utils.packageName(classe2.getPackageName())))){

                   if(!(this.listPranchetas.contains(classe2))){

                       for(XmiClass c : this.listPranchetas){
                       //if(classe2.getPackageName() != null){
                           if(utils.packageName(c.getPackageName()).equals(utils.packageName(classe2.getPackageName()))){
                               have2 = true;
                           }


                       }

                        if(!have2){
                            this.listPranchetas.add(classe2);
                        }


                   }

               }
               }

        }
           x++;
            }
       }

        for ( XmiClass classe2 : this.listPranchetas ){
            System.out.println("Prancheta : " + classe2.getName());
        }

        int y = 0;
        int t = 0;


        for(XmiClass abas : pack.getClasses()){
            boolean have = false;
            if(utils.packageName(abas.getPackageName()) != null){
            if (t == 0){

                this.listAbas.add(abas);
            }


            for(XmiClass abas2 : pack.getClasses()){
                if(utils.packageName(abas2.getPackageName()) != null){
               if(!(utils.subPackageName(abas.getPackageName()).equals(utils.subPackageName(abas2.getPackageName())))){

                   if(!(this.listAbas.contains(abas2))){

                       for(XmiClass c : this.listAbas){

                           if(utils.subPackageName(c.getPackageName()).equals(utils.subPackageName(abas2.getPackageName()))){
                               have = true;
                           }


                       }

                        if(!have){
                            if(!(abas2.getName().equals("String"))){
                            this.listAbas.add(abas2);
                            }
                        }


                   }
                       }
                   }

                 }


                 t++;


           }
        }




        for(XmiClass c : this.listAbas){
            System.out.println("Abas : " + c.getName());
        }






//        context2.put("inicialName" , this.prancheta);
        context2.put("listClass", this.listClass);
       // context2.put("Info", this.prancheta);
        context2.put("listAbas", listAbas);
        context2.put("listPranchetas", listPranchetas);
        Template template = velocity.getTemplate(tmpBlueTemplate
						.getAbsolutePath());
				template.merge(context2, output);
               // if(x == Application.getClasses().size() - 1 ){
                   // System.out.println("VEZ");
                    File dir;
                    dir = new File(outDir+"\\interface.jspx");

                    FileWriter f = new FileWriter(dir);
                    f.write(output.toString());
                    f.close();




          }



        private void generateClassFelipeProject(BlueTemplate tmpBlueTemplate , XmiPackage pack , String outDir , VelocityProcessor vp)

            throws ResourceNotFoundException, ParseErrorException, Exception {
                String appName = pack.getName();
                FelipeUtils utils = new FelipeUtils();






		for (XmiClass classe : pack.getClasses()) {

                    System.out.println("TESTANDO TESTANDO  " + classe.getPackageName());

                    //gerar classes da entity

                    if(classe.getPackageName().equals("entity")){
                        String x = this.getFirstAttr(classe);
                        context.put("firstAttr",x);
                        StringWriter output = new StringWriter();
                        context.put("class", classe);
		        Template template = velocity.getTemplate(tmpBlueTemplate
						.getAbsolutePath());
		        template.merge(context, output);

                        FilesParser file = new FilesParser(outDir);
				String classeName = classe.getName();

                                String fileName = vp.getFileName(tmpBlueTemplate, classe.getName());
                                this.generateEntityFiles(fileName, output
						.toString(), "entity", outDir);
//                                file.generateEntityFiles(fileName, output
//						.toString() , "entity");


                        context.remove("class");

                    }

                    //Gerar classes de associação

                    if((utils.packageName(classe.getPackageName()) != null) ){
		
				StringWriter output = new StringWriter();
				context.put("class", classe);
				context.put("subPackage", tmpBlueTemplate.getNameSubPackage());
                System.out.println(classe.getName());
                System.out.println(utils.packageName(classe.getPackageName()) + " pacote");
                System.out.println(utils.subPackageName(classe.getPackageName()) + " subpacote");
				Template template = velocity.getTemplate(tmpBlueTemplate
						.getAbsolutePath());
				template.merge(context, output);

				//FilesParser file = new FilesParser(outDir);
				String classeName = classe.getName();
				// modulo + SubPKG
				String module_PKG_Package = utils.packageName(classe.getPackageName());
                String module_PKG_SubPackage = utils.subPackageName(classe.getPackageName());
                String module_visualization = utils.visualization(classe.getPackageName());
										// file Name
				String fileName = vp.getFileName(tmpBlueTemplate, classe.getName());
                                this.generateFiles(fileName, module_PKG_Package,module_PKG_SubPackage,module_visualization,appName,output
						.toString(),outDir);
//				file.generateFiles(fileName, module_PKG_Package, module_PKG_SubPackage,module_visualization, appName, output
//						.toString());


				context.remove("class");
			}
		//}
                }


        }
        public ArrayList<Integer> getListMult() {
        return listMult;
    }

    public void setListMult(ArrayList<Integer> listMult) {
        this.listMult = listMult;
    }







}


